def max_subarray_sum(nums):
    max_sum=0
    cur=0
    for x in nums:
        cur = max(0, cur + x)
        max_sum = max(max_sum, cur)
    return max_sum
def main():
    line = input("请输入n和n个整数：\n")
    parts = line.strip().split()
    n = int(parts[0])
    nums = list(map(int, parts[1:]))
    if len(nums) != n:
        print("输入的整数个数与n一致！")
        return
    ans = max_subarray_sum(nums)
    print("最大子段和为：", ans)
if __name__ == "__main__":
    main()

